#!/bin/sh

. /opt/truecl/etc/clenv.sh

user=${1:-root}
h=`hostname`

r=`clreq --timeout 30 diskhb_check 2>&1 | 
	perl -ne 'BEGIN {@D=qw(junk req cluster network sync lock heartbeat status monitor);}
		if($. > 1) {
			chomp;
			@F=split(/:/);
			@F2=split(/\s+/,$F[2]);
			if($F2[1] ne "OK") {
				printf("Disk heartbeat \"$F[1]\" on host \"$F2[0]\" is not being updated.\n");
			}
		};'`

if [ -n "$r" ]
then
	if [ -x "/usr/bin/mailx" ]
	then
		echo "$r" | /usr/bin/mailx -s "Cluster disk heartbeat failures" $user
		exit 0
	fi
	if [ -x "/usr/bin/mail" ]
	then
		echo "Subject: Cluster disk heartbeat failures\n$r" | 
			/usr/bin/mail $user
	fi
fi

exit 0
